﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace PyramidShadow
{
    class FloorButton : LevelObject
    {
        private SpawnPoint spawnPoint;
        public SpawnPoint SpawnPoint
        {
            get { return spawnPoint; }
        }
        private Rectangle notPressed, pressed;
        private bool resseting;
        private bool activated;
        private bool flag = false;
        private PS_Event ps_event;

        public FloorButton(Texture2D texture, Vector2 position, Level level, Vector2 frameDim, Vector2 offset, bool resseting, PS_Event ps_event)
            : base(texture, position, level)
        {
            spawnPoint = new SpawnPoint(position);
            this.resseting = resseting;
            notPressed = new Rectangle(0,0,(int)frameDim.X,(int)frameDim.Y);
            pressed = new Rectangle((int)offset.X, (int)offset.Y, (int)frameDim.X, (int)frameDim.Y);
            this.ps_event = ps_event;
            activated = false;
        }

        public override void Update(GameTime gameTime, KeyboardState currentKeyboardState)
        {
            if (level.kollision.intersection(level.body.BoundingBox, boundingBox))
            {
                activated = true;
                if (!flag && activated)
                {
                    ps_event.doIt();
                    flag = true;
                }
            }

            else
                if (resseting)
                {
                    activated = false;
                    flag = false;
                }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            if (activated)
                spriteBatch.Draw(texture, boundingBox, pressed, Color.White);
            else
                spriteBatch.Draw(texture, boundingBox, notPressed, Color.White);
        }
    }
}
